//
//  ClassifyViewController.m
//  EcShop
//
//  Created by soft on 2017/11/8.
//  Copyright © 2017年 soft. All rights reserved.
//

#import "ClassifyViewController.h"
#import "AllType.h"
#import "HTTPMananger.h"
#import "TypeCell.h"
#import "UIImageView+WebCache.h"
#import "MinuteViewController.h"
@interface ClassifyViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray <AllType *>* typeList;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ClassifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title =@"111111";
  //  self.view.backgroundColor = [UIColor redColor];
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    [self.tableView registerNib:[UINib nibWithNibName:@"TypeCell" bundle:nil] forCellReuseIdentifier:@"typeCell"];
    self.tableView.rowHeight = 75;
    
    [[HTTPMananger sharedManager] classifyProduct:^(NSDictionary *object, NSError *error) {
        if (error) {
            
            return;
        }
        self.typeList = [AllType mj_objectArrayWithKeyValuesArray:object[@"superCategory"]];
        [self.tableView reloadData];
        
        NSLog(@"%@",self.typeList);
        
    }];
    // Do any additional setup after loading the view.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.typeList.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"typeCell" forIndexPath:indexPath];
//    TypeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"typeCell"];
//    // 判断如果没有可以重用的cell，创建
//    if (!cell) {
//        cell = [[TypeCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"typeCell"];
//    }
    //    UILabel *showlabel=[cell viewWithTag:1];
    //showlabel.text=self.typeList[indexPath.row].TypeName;
    UILabel *oneLabel = [cell viewWithTag:1];
    oneLabel.text=self.typeList[indexPath.row].TypeName;
    UILabel *twoLabel = [cell viewWithTag:2];
    twoLabel.text = self.typeList[indexPath.row].category.firstObject.name;
    UILabel *threeLabel = [cell viewWithTag:3];
    threeLabel.text =self.typeList[indexPath.row].category.lastObject.name;
    NSString *url = [NSString stringWithFormat:@"https://cdnme.azurewebsites.net/image/imagesize?filename=%@&param=%@",self.typeList[indexPath.row].category.firstObject.pic,@"100x100"];
    UIImageView *imageView=[cell viewWithTag:4];
    [imageView sd_setImageWithURL:[NSURL URLWithString:url]];
    //  cell.textLabel.textColor=[UIColor darkGrayColor];
    // cell.backgroundColor= [UIColor yellowColor];
    //  cell.imageView.image=[UIImage imageNamed:@"右箭头"];
    // cell.imageView.image =;
    
    
    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    UIViewController *VC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"minute"];
//    NSArray *arr = self.typeList[indexPath.row].category;
//    
//    [VC setValue:arr forKey:@"theAllType"];
//    [self.navigationController pushViewController:VC animated:YES];
    
    
    MinuteViewController *prv = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"minute"];
    NSArray *arr = self.typeList[indexPath.row].category;
    [prv setValue:arr forKey:@"theAllType"];
    [self.navigationController pushViewController:prv animated:YES];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
